package com.service.impl;

import com.bean.entity.City;
import com.bean.entity.Classes;
import com.bean.pojo.PageAssistant;
import com.bean.vo.ClassesVo;
import com.dao.CityMapper;
import com.dao.ClassesMapper;
import com.service.CityService;
import com.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 班级基础业务逻辑实现
 */
@Service
public class ClassesServiceImpl implements ClassesService {

    @Autowired
    private ClassesMapper classesMapper;

    public int save(Classes t) throws Exception {
        return classesMapper.insert(t);
    }

    public int remove(Classes t) throws Exception {
        return classesMapper.delete(t);
    }

    public int modify(Classes t) throws Exception {
        return classesMapper.update(t);
    }

    public ClassesVo unique(Classes t) throws Exception {
        List<ClassesVo> classesVoList = classesMapper.select(t);
        if (classesVoList.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return classesVoList.get(0);
    }

    public List<ClassesVo> query(Classes t) {
        return classesMapper.select(t);
    }

    public PageAssistant<ClassesVo> queryByPage(Map<String, Object> map, PageAssistant<ClassesVo> pa) {
        //查询并设置总记录数
        pa.setCount(classesMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(classesMapper.selectByPage(map));
        return pa;
    }
}
